package com.cly;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import lombok.Data;
import lombok.experimental.Accessors;

import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;

/**
 * 代码生成器
 *
 * @author by 春风能解释
 * <p>
 * 2024/6/5
 */
public class GeneratorMain {
    /**
     * 主方法
     *
     * @param args 参数
     */
    public static void main(String[] args) {
        List<Config> configs = Arrays
                .asList(
                        new Config()
                                .setDatabaseName("smart_villages_permission"),
                        new Config()
                                .setDatabaseName("smart_villages_course"),
                        new Config()
                                .setDatabaseName("smart_villages_document"),
                        new Config()
                                .setDatabaseName("smart_villages_message"),
                        new Config()
                                .setDatabaseName("smart_villages_recruit"),
                        new Config()
                                .setDatabaseName("smart_villages_work")

                );
        configs.forEach(v -> FastAutoGenerator
                .create("jdbc:mysql://localhost:3306/" + v.databaseName, "root", "13597803422dw")
                .globalConfig(builder -> builder
                        .author("春风能解释")
                        .outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java")
                        .commentDate("yyyy-MM-dd")
                        .enableSwagger()
                        .enableSpringdoc()
                )
                .packageConfig(builder -> builder
                        .parent("com.cly")
                        .entity("entity")
                        .mapper("mapper")
                        .service("service")
                        .serviceImpl("service.impl")
                        .xml("xml")
                )
                .strategyConfig(builder -> builder
                        .entityBuilder()
                        .enableLombok()
                        .enableFileOverride()
                        .enableChainModel()
                )
                .templateEngine(new FreemarkerTemplateEngine())
                .execute());
    }

    /**
     * 自定义配置
     */
    @Data
    @Accessors(chain = true)
    public static class Config {
        /**
         * 数据库名称
         */
        private String databaseName;
        /**
         * 父包名
         */
        private String parent;
    }
}
